#pragma once
typedef struct {
	datatype data;
	BiTreeNode* leftchild;
	BiTreeNode* rightchild;
}BiTreeNode;

void InitiateTree(BiTreeNode** root)
{
	*root = (BiTreeNode*)malloc(sizeof(BiTreeNode));
	(*root)->leftchild = NULL;
	(*root)->rightchild = NULL;
}

BiTreeNode* InsertLeftNode(BiTreeNode* curr, datatype x)
{
	if (curr == NULL)
	{
		return NULL;
	}
	BiTreeNode* p, * q;
	q = curr->leftchild;
	p = (BiTreeNode*)malloc(sizeof(BiTreeNode));
	p->data = x;
	p->leftchild = q;
	p->rightchild = NULL;
	curr->leftchild = q;
	return curr->leftchild;
}

BiTreeNode* InsertRightNode(BiTreeNode* curr, datatype x)
{
	if (curr == NULL)return NULL;
	BiTreeNode* p, * q;
	p = (BiTreeNode*)malloc(sizeof(BiTreeNode));
	q = curr->rightchild;
	p->data = x;
	p->leftchild = NULL;
	p->rightchild = q;
	curr->rightchild = p;
	return curr->rightchild;
}

BiTreeNode* DeleteLeftTree(BiTreeNode* curr)
{
	if (curr == NULL || curr->leftchild == NULL)return NULL;
	Destroy(&curr->leftchild);
	curr->leftchild = NULL;
	return curr;
}

BiTreeNode* DeleteRightTree(BiTreeNode* curr)
{
	if (curr == NULL || curr->rightchild == NULL)return NULL;
	Destroy(&curr->rightchild);
	curr->rightchild = NULL;
	return curr;
}